package com.dt.dubai.mech.service;

import com.dt.dubai.mech.entity.MechMarketingCouponEntity;
import com.dt.dubai.mech.service.innate.MechMarketingCouponSerInnateAbsImp;
import com.dt.dubai.mech.service.ser.MechCouponCustomerService;
import com.dt.dubai.mech.service.ser.MechMarketingCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class MechMarketingCouponServiceImp extends MechMarketingCouponSerInnateAbsImp implements MechMarketingCouponService {

    /*innateServiceStart*/
    @Override
    protected void userSavEntity(MechMarketingCouponEntity inEntity) {

    }

    @Override
    protected void userModEntity(MechMarketingCouponEntity inEntity, MechMarketingCouponEntity upEntity) {
        upEntity.setAdminLoginRecordId(inEntity.getAdminLoginRecordId()); // 商户登录记录ID
        upEntity.setCommodityType(inEntity.getCommodityType()); // 类型
        upEntity.setCouponPublishType(inEntity.getCouponPublishType()); // 优惠券发行类型
        upEntity.setCouponName(inEntity.getCouponName()); // 优惠券名称
        upEntity.setPublishNum(inEntity.getPublishNum()); // 发行量
        upEntity.setPublishPrice(inEntity.getPublishPrice()); // 发行价
        upEntity.setCouponRuleJson(inEntity.getCouponRuleJson()); // 优惠券规则
        upEntity.setScopeUseJson(inEntity.getScopeUseJson()); // 使用范围
        upEntity.setRetailCommodityRecordId(inEntity.getRetailCommodityRecordId()); // 商品记录id
        upEntity.setCommodityInfoJson(inEntity.getCommodityInfoJson()); // 商品销售属性
        upEntity.setStartUseTime(inEntity.getStartUseTime()); // 开始使用时间
        upEntity.setEndUseTime(inEntity.getEndUseTime()); // 结束使用时间

    }

    /*innateServiceEnd*/
    /*以上内容请误删除或是移动，系统升级使用，static系统升级覆盖用户修改，用户代码请写入下方*/
    @Autowired
    MechCouponCustomerService mechCouponCustomerSer;

    @Override
    public List<MechMarketingCouponEntity> findListByUseStatus(Boolean useStatus, Long userId) {
        List<MechMarketingCouponEntity> objects = new ArrayList<>();
        List<Long> longs = mechCouponCustomerSer.selectRecordIdByCustomerAndUseStatus(userId, useStatus);
        if(1>longs.size()){
            for (Long recordId : longs) {
                MechMarketingCouponEntity mechMarketingCouponEntity = this.byKeyRecordId(recordId,userId);
                objects.add(mechMarketingCouponEntity);
            }
        }
        return objects;
    }
}
